package blue.mqtt4j.client;

import blue.mqtt4j.client.codec.Encoder;

import java.util.List;

/**
 * MQTT 发送接口
 *
 * @author Jin Zheng
 * @since 1.0 2020-09-30
 */
public interface Producer
{

	default void sendSync(MqttMessage message)
	{
		this.sendSync(List.of(message), null);
	}

	default void sendSync(MqttMessage message, Encoder encoder)
	{
		this.sendSync(List.of(message), encoder);
	}

	default void sendSync(List<MqttMessage> messageList)
	{
		this.sendSync(messageList, null);
	}

	/**
	 * 同步发送
	 *
	 * @param messageList
	 * @param encoder
	 */
	void sendSync(List<MqttMessage> messageList, Encoder encoder);

	default void sendAsync(MqttMessage message)
	{
		this.sendAsync(List.of(message), null, null);
	}

	default void sendAsync(MqttMessage message, ProducerListener listener)
	{
		this.sendAsync(List.of(message), null, listener);
	}

	default void sendAsync(MqttMessage message, Encoder encoder)
	{
		this.sendAsync(List.of(message), encoder, null);
	}

	default void sendAsync(MqttMessage message, Encoder encoder, ProducerListener listener)
	{
		this.sendAsync(List.of(message), encoder, listener);
	}

	default void sendAsync(List<MqttMessage> messageList)
	{
		this.sendAsync(messageList, null, null);
	}

	default void sendAsync(List<MqttMessage> messageList, ProducerListener listener)
	{
		this.sendAsync(messageList, null, listener);
	}

	default void sendAsync(List<MqttMessage> messageList, Encoder encoder)
	{
		this.sendAsync(messageList, encoder, null);
	}

	/**
	 * 异步发送
	 *
	 * @param messageList
	 * @param listener
	 */
	void sendAsync(List<MqttMessage> messageList, Encoder encoder, ProducerListener listener);

	void setProducerListener(ProducerListener listener);

	void setEncoder(Encoder encoder);

}
